package org.groupg.practice;

import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;

public class FastUtilFrequencyExample {
    public static void main(String[] args) {
        // 用于词频统计的 Map
        Object2IntOpenHashMap<String> wordCounts = new Object2IntOpenHashMap<>();
        // 设置默认返回值，当键不存在时返回0
        wordCounts.defaultReturnValue(0);

        String[] words = {"apple", "banana", "apple", "orange", "banana", "apple"};

        for (String word : words) {
            // 使用 addTo 方法为指定键的值增加增量，不存在则从默认值开始
            wordCounts.addTo(word, 1);
        }

        // 获取 "apple" 的频率
        int appleCount = wordCounts.getInt("apple");
        System.out.println("Count of 'apple': " + appleCount); // 输出: Count of 'apple': 3
    }
}